package ejb.cbm.admin.session;

import java.util.List;

import javax.persistence.EntityManager;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import ejb.cbm.admin.entity.TransaccionEntity;
import ejb.cbm.admin.local.TransaccionSessionLocal;

////@Stateless
public class TransaccionSession extends HibernateDaoSupport implements TransaccionSessionLocal {
	
	static Logger logger = Logger.getLogger(TransaccionSession.class.getName());
	//property constants
	public static final String CODIGOTRANSACCIONHOST = "codigotransaccionhost";
	public static final String DESCRIPCIONTRANSACCION = "descripciontransaccion";
	public static final String FLAGHABILITAR = "flaghabilitar";
	public static final String FLAGAFECTASALDO = "flagafectasaldo";
	public static final String FLAGSALDODISPONIBLE = "flagsaldodisponible";
	public static final String FLAGSALDOCONTABLE = "flagsaldocontable";
	public static final String FLAGSIGNIFICATIVO = "flagsignificativo";
	public static final String FLAGAUTORIZACION = "flagautorizacion";
	public static final String FLAGENVIARHOST = "flagenviarhost";
	public static final String FLAGRENIEC = "flagreniec";
	public static final String FLAGVALIDARSALDO = "flagvalidarsaldo";
	public static final String FLAGCTASRESTRINGIDAS = "flagctasrestringidas";
	public static final String FLAGVISIBLE = "flagvisible";
	public static final String CODIGOFORMATOIMPRESION = "codigoformatoimpresion";
	public static final String FLAGACTIVO = "flagactivo";
	public static final String USUARIOREGISTRO = "usuarioregistro";
	public static final String USUARIOMODIFICACION = "usuariomodificacion";


    //@PersistenceContext 
    private EntityManager entityManager;
    public void save(TransaccionEntity transientInstance) {
    	logger.log("saving TransaccionEntity instance", Level.INFO, null,null);
        try {
            entityManager.persist(transientInstance);
            logger.log("save successful", Level.INFO, null,null);
        } catch (RuntimeException re) {
        	logger.log("save failed", Level.FATAL,null, re);
            throw re;
        }
    }
    
    public void delete(TransaccionEntity persistentInstance) {
    	logger.log("deleting TransaccionEntity instance", Level.INFO, null,null);
        try {
            entityManager.remove(persistentInstance);
            logger.log("delete successful", Level.INFO, null,null);
        } catch (RuntimeException re) {
        	logger.log("delete failed", Level.FATAL,null, re);
            throw re;
        }
    }
    
    public TransaccionEntity update(TransaccionEntity detachedInstance) {
    	logger.log("updating TransaccionEntity instance", Level.INFO, null,null);
        try {
            TransaccionEntity result = entityManager.merge(detachedInstance);
            logger.log("update successful", Level.INFO, null,null);
            return result;
        } catch (RuntimeException re) {
        	logger.log("update failed", Level.FATAL,null, re);
            throw re;
        }
    }
    
    public TransaccionEntity findById( Long id) {
    	logger.log("finding TransaccionEntity instance with id: " + id, Level.INFO, null,null);
        try {
            TransaccionEntity instance = entityManager.find(TransaccionEntity.class, id);
            return instance;
        } catch (RuntimeException re) {
        	logger.log("find failed", Level.FATAL,null, re);
            throw re;
        }
    }
    
    //@SuppressWarnings("unchecked")
    public List<TransaccionEntity> findByProperty(String propertyName, Object value) {
    	logger.log("finding TransaccionEntity instance with property: " + propertyName
    						+ ", value: " + value, Level.INFO,null, null);
		try {
			String queryString = "select model from TransaccionEntity model where model." 
			 						+ propertyName + "= :propertyValue";
			return entityManager.createQuery(queryString)
 				.setParameter("propertyValue", value).getResultList();
		} catch (RuntimeException re) {
			logger.log("find by property name failed", Level.FATAL,null, re);
			throw re;
		}
	}
	
	public List<TransaccionEntity> findByCodigotransaccionhost(Object codigotransaccionhost) {
		return findByProperty(CODIGOTRANSACCIONHOST, codigotransaccionhost);
	}
	
	public List<TransaccionEntity> findByDescripciontransaccion(Object descripciontransaccion) {
		return findByProperty(DESCRIPCIONTRANSACCION, descripciontransaccion);
	}
	
	public List<TransaccionEntity> findByFlaghabilitar(Object flaghabilitar) {
		return findByProperty(FLAGHABILITAR, flaghabilitar);
	}
	
	public List<TransaccionEntity> findByFlagafectasaldo(Object flagafectasaldo) {
		return findByProperty(FLAGAFECTASALDO, flagafectasaldo);
	}
	
	public List<TransaccionEntity> findByFlagsaldodisponible(Object flagsaldodisponible) {
		return findByProperty(FLAGSALDODISPONIBLE, flagsaldodisponible);
	}
	
	public List<TransaccionEntity> findByFlagsaldocontable(Object flagsaldocontable) {
		return findByProperty(FLAGSALDOCONTABLE, flagsaldocontable);
	}
	
	public List<TransaccionEntity> findByFlagsignificativo(Object flagsignificativo) {
		return findByProperty(FLAGSIGNIFICATIVO, flagsignificativo);
	}
	
	public List<TransaccionEntity> findByFlagautorizacion(Object flagautorizacion) {
		return findByProperty(FLAGAUTORIZACION, flagautorizacion);
	}
	
	public List<TransaccionEntity> findByFlagenviarhost(Object flagenviarhost) {
		return findByProperty(FLAGENVIARHOST, flagenviarhost);
	}
	
	public List<TransaccionEntity> findByFlagreniec(Object flagreniec) {
		return findByProperty(FLAGRENIEC, flagreniec);
	}
	
	public List<TransaccionEntity> findByFlagvalidarsaldo(Object flagvalidarsaldo) {
		return findByProperty(FLAGVALIDARSALDO, flagvalidarsaldo);
	}
	
	public List<TransaccionEntity> findByFlagctasrestringidas(Object flagctasrestringidas) {
		return findByProperty(FLAGCTASRESTRINGIDAS, flagctasrestringidas);
	}
	
	public List<TransaccionEntity> findByFlagvisible(Object flagvisible) {
		return findByProperty(FLAGVISIBLE, flagvisible);
	}
	
	public List<TransaccionEntity> findByCodigoformatoimpresion(Object codigoformatoimpresion) {
		return findByProperty(CODIGOFORMATOIMPRESION, codigoformatoimpresion);
	}
	
	public List<TransaccionEntity> findByFlagactivo(Object flagactivo) {
		return findByProperty(FLAGACTIVO, flagactivo);
	}
	
	public List<TransaccionEntity> findByUsuarioregistro(Object usuarioregistro) {
		return findByProperty(USUARIOREGISTRO, usuarioregistro);
	}
	
	public List<TransaccionEntity> findByUsuariomodificacion(Object usuariomodificacion) {
		return findByProperty(USUARIOMODIFICACION, usuariomodificacion);
	}
	

	//@SuppressWarnings("unchecked")
	public List<TransaccionEntity> findAll() {
		logger.log("finding all TransaccionEntity instances", Level.INFO, null,null);
		try {
			String queryString = "select model from TransaccionEntity model";
			return entityManager.createQuery(queryString).getResultList();
		} catch (RuntimeException re) {
			logger.log("find all failed", Level.FATAL,null, re);
			throw re;
		}
	}
}